package com.idea.cery.springboot1.controller;

import com.idea.cery.springboot1.bean.UserOrderInfo;
import com.idea.cery.springboot1.mapper.MybatisDao;
import com.idea.cery.springboot1.service.MybatisService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.idea.cery.springboot1.entity.User;

import java.util.List;

/**
 * @author cery
 */
@Api(description = "Mybatis 数据库操作")
@RestController
@RequestMapping("mb")
public class MybatisController {

    @Autowired
    MybatisService mybatisService;
    @Autowired
    MybatisDao     mybatisDao;

    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index() {
        System.out.println("进入mybatis controller");
        return "mybatis";
    }

    @RequestMapping(value = "add", method = RequestMethod.GET)
    public String mbAdd() {
        User user = new User();
        user.setId("5");
        user.setName("hsh");
        user.setAge(22);
        user.setStatus("1");
        return mybatisService.add(user);
    }

    @RequestMapping(value = "del", method = RequestMethod.GET)
    public String mbDel(String id) {

        return mybatisService.del(id);
    }

    @RequestMapping(value = "upd", method = RequestMethod.GET)
    public String mbUpd() {
        User user = new User();
        user.setId("5");
        user.setName("hsh");
        user.setAge(18);
        user.setStatus("1");

        return mybatisService.upd(user);
    }

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public List<User> mbList() {

        return mybatisService.list();
    }

    @RequestMapping(value = "one", method = RequestMethod.GET)
    public List<UserOrderInfo> mbUnion() {

        return mybatisDao.getOrderByName("1");
    }
}
